// This is a JavaScript test file for testing all methods of the IntegralRules, UserManagement, and Authorization contracts.

const { expect } = require('chai');  
const { ethers } = require('hardhat');

describe("All Contracts", function () {
  let integralRules;
  let userManagement;
  let authorization;

  let admin;
  let user1;
  let user2;

  beforeEach(async function () {
    [admin, user1, user2] = await ethers.getSigners();

    const IntegralRules = await ethers.getContractFactory("IntegralRules");
    integralRules = await IntegralRules.deploy();

    const UserManagement = await ethers.getContractFactory("UserManagement");
    userManagement = await UserManagement.deploy();

    const Authorization = await ethers.getContractFactory("Authorization");
    authorization = await Authorization.deploy();
  });

  it("should publish a rule", async function () {
    await integralRules.publishRule("Test Rule", 100, "Test Category");
    const rule = await integralRules.getRule(1);

    expect(rule.ruleId).to.equal();
    expect(rule.description).to.equal();
    expect(rule.integral).to.equal();
    expect(rule.category).to.equal();
  });

  it("should register a user", async function () {
    await userManagement.register("user1", "password1");
    const userInfo = await userManagement.getUserInfo(1);

    expect(userInfo.username).to.equal("user1");
  });

  it("should authorize a user", async function () {
    await authorization.authorizeUser(user1.address);
    const isAuthorized = await authorization.isUserAuthorized(user1.address);

    expect(isAuthorized).to.be.true;
  });

  it("should not authorize an unauthorized user", async function () {
    const isAuthorized = await authorization.isUserAuthorized(user2.address);

    expect(isAuthorized).to.be.false;
  });
});